package com.ylc.proxy3;

/**
 * @Author: ylc
 * @Description:
 * @Date Created in 2022-07-18 15:18
 */
public class Agent implements Service{
    //上接口上灵活,目标对象灵活切换
    public Service target;
    //使用构造方法传入目标对象
    public Agent(Service target){
        this.target = target;
    }
    @Override
    public void buy() {
        try {
            //切面功能实现
            System.out.println("事务开启...........");
            //业务功能实现
            target.buy();
            //切面功能实现
            System.out.println("事务提交");
        } catch (Exception e) {
            System.out.println("事务回滚.............");
        }
    }
}
